package model;

import java.util.List;
import java.util.LinkedList;
import java.util.Observable;

import model.building.Building;
import model.util.Vector3D;
import model.util.Object3D;

public class City extends Observable {

    /** Attributs */
    private Ressources m_economy;
    private List<Building> m_buildingList;
	
    /** Constructeurs */
    public City(Ressources economy) {
        m_economy = economy;
        m_buildingList = new LinkedList<Building>();
    }

    /** Accesseurs */
    public Ressources getEconomy() { return m_economy; }

    /** Methodes */
    public boolean canBuild(Object3D object3d) {
        for (Building buildingDone : m_buildingList)
            if (buildingDone.getObject3D().intersects(object3d)) return false;
        return true;
    }

    public boolean canBuild(Object3D.Shape3D shape3d, Vector3D position) {
        for (Building buildingDone : m_buildingList)
            if (shape3d.intersects(position, buildingDone.getObject3D())) return false;
        return true;
    }

    public synchronized void add(Building building) { m_buildingList.add(building); }

    public synchronized void remove(Building building) { m_buildingList.remove(building); }

    public synchronized void update(double deltaTps) 
    { for (Building building : m_buildingList) building.update(deltaTps); }

}